// 路由配置文件
import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';

import HomeView from '@/views/HomeView.vue';
export const constantRoutes: RouteRecordRaw[] = [
    {
        path: '/',
        name: 'home',
        meta: { title: '地图平台' },
        component: HomeView
        // component: () => import("@/views/home/index.vue"),
        // children: []
    },
    {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('@/views/AboutView.vue')
    }
];

const router = createRouter({
    history: createWebHashHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
    routes: constantRoutes,
    // 刷新时，滚动条位置还原
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        }
        return { top: 0 };
    }
});

// router.beforeEach((to, from, next) => {
//     next()
// })

export default router;
